<template>
  <div>
    <wraptitle>
      <template v-slot:view-title
        >简历点评（共计：{{ totalcount }}条）</template
      >
    </wraptitle>
    <el-table
      :data="resumeComments"
      border
      size="mini"
      stripe
      style="width: 100%"
    >
      <el-table-column
        prop="resume_id.file_name"
        label="简历文件名"
        show-overflow-tooltip
        min-width="120"
      ></el-table-column>
      <el-table-column
        prop="experts_id.experts_name"
        label="评论者"
        width="120"
      ></el-table-column>
      <el-table-column
        prop="content"
        label="评论内容"
        show-overflow-tooltip
        min-width="300"
      ></el-table-column>
      <el-table-column
        prop="create_time"
        label="创建时间"
        width="150"
      ></el-table-column>
      <el-table-column label="操作" fixed="right" width="56">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            circle
            :disabled="disabled"
            @click="underComments(scope.row)"
          >
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页部分 -->
    <div class="pagination" v-show="totalcount > 10">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="pagesize"
        @current-change="pageChange"
        :current-page.sync="currentPage"
        :total="totalcount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import wraptitle from '../../components/content/WrapTitle'
import { getResumeComents, deleteComments } from '@/network/resume'
import { mapGetters } from 'vuex'

export default {
  name: 'resumecoment',
  components: {
    wraptitle
  },
  computed: {
    ...mapGetters(['roleid', 'userid'])
  },
  data() {
    return {
      totalcount: 0,
      pagesize: 10,
      currentPage: 0,
      resumeComments: [],
      disabled: true
    }
  },
  created() {
    this.disabled = this.roleid < 3 ? true : false
    this.getList()
  },
  methods: {
    getList() {
      let params = {}
      params.user_id = this.roleid > 2 ? '' : this.userid
      params.is_author = this.roleid > 2 ? '' : 0
      params.pagenow = this.pagenow
      getResumeComents(params).then(res => {
        if (res.code === 200) {
          this.resumeComments = res.data.data
          this.totalcount = res.data.totalcount
        }
        if (res.code === 401) {
          this.$toast(res.message, 'error')
        }
      })
    },

    pageChange(currentPage) {
      this.pagenow = currentPage
      this.currentPage = currentPage
      this.getList()
    },
    underComments(comments) {
      console.log()
      this.showDialog('此操作会删除该点评, 是否继续?', () => {
        deleteComments({ comments_id: comments.comments_id })
          .then(res => {
            this.$toast('已删除')
            this.getList()
          })
          .catch(err => {
            this.$toast(err.message, 'error')
          })
      })
    },
    showDialog(tip, next) {
      this.$confirm(tip, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      })
        .then(() => {
          next()
        })
        .catch(() => {})
    }
  }
}
</script>

<style lang="scss">
.toolbar {
  padding: 20px;
  display: flex;
  flex-direction: row;

  .input-wrap {
    display: flex;
    height: 42px;
    width: 100%;
    line-height: 42px;
    justify-content: space-evenly;

    .toolbar-input {
      margin-top: -1px;
    }
  }
}
.pagination {
  margin: 20px;
  text-align: center;
}
.el-pagination {
  justify-content: center;
}
</style>
